#include "RsGisLibUtiAssignSpatialInfo.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibUtiAssignSpatialInfo::RsGisLibUtiAssignSpatialInfo(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibUtiAssignSpatialInfo();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_InputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_InputFilePath_clicked()));
	connect(ui->pushButton_Excecute, SIGNAL(clicked()), this, SLOT(on_action_Button_Excecute_clicked()));

	ui->lineEdit_InputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\In");

	QStringList FlagList;
	FlagList.append("False");
	FlagList.append("True");
	ui->comboBox_xTLDef->addItems(FlagList);
	ui->comboBox_yTLDef->addItems(FlagList);
	ui->comboBox_xResDef->addItems(FlagList);
	ui->comboBox_yResDef->addItems(FlagList);
	ui->comboBox_xRotDef->addItems(FlagList);
	ui->comboBox_yRotDef->addItems(FlagList);

	ui->lineEdit_xTL->setText("0.0");
	ui->lineEdit_yTL->setText("0.0");
	ui->lineEdit_xRes->setText("0.0");
	ui->lineEdit_yRes->setText("0.0");
	ui->lineEdit_xRot->setText("0.0");
	ui->lineEdit_yRot->setText("0.0");
	ui->comboBox_xTLDef->setCurrentIndex(0);
	ui->comboBox_yTLDef->setCurrentIndex(0);
	ui->comboBox_xResDef->setCurrentIndex(0);
	ui->comboBox_yResDef->setCurrentIndex(0);
	ui->comboBox_xRotDef->setCurrentIndex(0);
	ui->comboBox_yRotDef->setCurrentIndex(0);

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibUtiAssignSpatialInfo::on_action_Button_InputFilePath_clicked()
{
	QString str = QFileDialog::getOpenFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "All file(*.*)");
	ui->lineEdit_InputFilePath->setText(str.toUtf8());
}

void RsGisLibUtiAssignSpatialInfo::on_action_Button_Excecute_clicked()
{
	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("ImageUtils"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("AssignSpatialInfo"));
	AlgParaList << QVariant(QString(ui->lineEdit_InputFilePath->text()));
	AlgParaList << QVariant(double(ui->lineEdit_xTL->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_yTL->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_xRes->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_yRes->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_xRot->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_yRot->text().toDouble()));
	AlgParaList << QVariant(int(ui->comboBox_xTLDef->currentIndex()));
	AlgParaList << QVariant(int(ui->comboBox_yTLDef->currentIndex()));
	AlgParaList << QVariant(int(ui->comboBox_xResDef->currentIndex()));
	AlgParaList << QVariant(int(ui->comboBox_yResDef->currentIndex()));
	AlgParaList << QVariant(int(ui->comboBox_xRotDef->currentIndex()));
	AlgParaList << QVariant(int(ui->comboBox_yRotDef->currentIndex()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}